﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using ZWQBlog.Model;
using ZWQBlog.Repository.Contract;

namespace ZWQBlog.Repository
{
    public class ZWQBlogContext : ObjectContext , IContext
    {
        private ObjectSet<Post> _posts;
        private ObjectSet<Category> _categories;
        private ObjectSet<Comment> _comments;
        private ObjectSet<Author> _authors;
        private ObjectSet<Role> _roles;
        private ObjectSet<User> _users;

        public ZWQBlogContext()
            : base("name=ZWQBlogContainer", "ZWQBlogContainer")
        {
            _comments = CreateObjectSet<Comment>();
            _posts = CreateObjectSet<Post>();
            _categories = CreateObjectSet<Category>();
            _authors = CreateObjectSet<Author>();
            _roles = CreateObjectSet<Role>();
            _users = CreateObjectSet<User>();
        }

        public ObjectSet<User> Users
        {
            get { return _users; }
        }

        public ObjectSet<Role> Roles
        {
            get { return _roles; }
        }

        public ObjectSet<Author> Authors
        {
            get { return _authors; }
        }

        public ObjectSet<Comment> Comments
        {
            get { return _comments; }
        }

        public ObjectSet<Category> Categories
        {
            get { return _categories; }
        }

        public ObjectSet<Post> Posts
        {
            get { return _posts; }
        }

        public void Commit()
        {
            this.SaveChanges();
        }
    }
}
